// writer: Milkcat
// time: 2024.2.24 11:29
#include <bits/stdc++.h>
#define REP(i, l, r) for (int i = (l); i <= (r); ++ i)
#define DEP(i, r, l) for (int i = (r); i >= (l); -- i)
#define fi first
#define se second
#define pb emplace_back
#define mems(x, v) memset((x), (v), sizeof(x))
using namespace std;
namespace Milkcat {
	typedef long long LL;
	typedef __int128 i128;
	typedef pair<i128, i128> pii;
	const int N = 1e6 + 5, mod = 998244353;
	LL n, t; i128 ans, c[N], v[N], x[N];
	vector<pii> q;
	int main() {
		cin >> n, q.clear();
		REP(i, 1, n) cin >> t, v[i] = t;
		REP(i, 1, n) cin >> t, c[i] = t;
		REP(i, 2, n) cin >> t, x[i] = t;
		q.pb(v[1], c[1]), ans = v[1] * c[1];
		REP(i, 2, n) {
			if (x[i] > 1) {
				i128 sv = 0, sc = 0; vector<pii> p;
				while (q.size()) {
					auto [s, ct] = q.back(); q.pop_back();
					if (sc > 0) {
						i128 w = min(ct, x[i] - sc);
						sc += w, sv += w * s, ct -= w;
						if (sv > 1e10) break;
						if (sc == x[i]) p.pb(sv, 1), sv = sc = 0;
						else continue;
					}
					if (s * x[i] > 1e10) break;
					p.pb(s * x[i], ct / x[i]), ct %= x[i];
					sc = ct, sv = s * ct;
				}
				reverse(p.begin(), p.end()), p.swap(q);
			}
			while (q.size() && q.back().fi < v[i]) {
				auto [s, ct] = q.back();
				ans -= s * ct, c[i] += ct, q.pop_back();
			}
			ans += c[i] * v[i], q.pb(v[i], c[i]);
		}
		cout << (LL)(ans % mod) << '\n';
		return 0;
	}
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	freopen("b.in","r",stdin);
    freopen("b.out","w",stdout);
	Milkcat::main();
	return 0;
}
